﻿using System;
using NEasy.Ldap;
using NEasyLdap.Tests.Entity;
using NUnit.Framework;

// ReSharper disable InconsistentNaming
// ReSharper disable SuggestUseVarKeywordEvident
namespace NEasyLdap.Tests.BasicAccessTests
{
    [TestFixture()]
    public class Find_UserWithComment_In_AD_
    {
        private LdapRepository sut;

        [SetUp()]
        public void Setup()
        {
            Console.WriteLine();

            sut = new LdapRepository(
                new LdapDomainInfo("mentzel.org", "DC=Mentzel,DC=org"));
        }

        [Test()]
        public void Find_Administrator()
        {
            var person = sut.Find(new UserWithComment() { SAMAccountName = "Administrator" });

            Assert.That(person, Is.Not.Null);
            Assert.That(person.SAMAccountName, Is.EqualTo("Administrator"));

            Console.WriteLine(string.Format("samAccoutName={0}", person.SAMAccountName));
            Console.WriteLine(string.Format("objectClass={0}", person.ObjectClass));
            Console.WriteLine(string.Format("comment={0}", person.Comment));
            Console.WriteLine(string.Format("CN={0}", person.CanonicalName));
        }

        [Test()]
        public void Find_Non_Existing()
        {
            var person = sut.Find(new UserWithComment() { SAMAccountName = "NotExistingUser" });

            Assert.That(person, Is.Null);
        }

        [Test()]
        public void Find_Administrators_Group()
        {
            var person = sut.Find(new UserWithComment() { SAMAccountName = "Administrators" });

            Assert.That(person, Is.Not.Null);
            Assert.That(person.SAMAccountName, Is.Not.Null);

            Console.WriteLine(string.Format("samAccoutName={0}", person.SAMAccountName));
            Console.WriteLine(string.Format("comment={0}", person.Comment));
        }

        [Test()]
        public void Update_Administrator_With_Null_Value()
        {
            var person = sut.Find(new UserWithComment() { SAMAccountName = "Administrator" });

            person.Comment = null;
            sut.Update(person);


            Console.WriteLine(string.Format("samAccoutName={0}", person.SAMAccountName));
            Console.WriteLine(string.Format("objectClass={0}", person.ObjectClass));
            Console.WriteLine(string.Format("comment={0}", person.Comment));
            Console.WriteLine(string.Format("CN={0}", person.CanonicalName));
        }


    }
}
